package pers.jsan.litheopen.openserver.user.service.impl;

import com.alibaba.fastjson.JSONObject;
import pers.jsan.litheopen.security.oauth.model.UserDetail;
import pers.jsan.litheopen.security.oauth.service.IUserDetailService;
import pers.jsan.litheopen.openserver.user.entity.LitheUser;
import pers.jsan.litheopen.openserver.user.mapper.LitheUserMapper;
import pers.jsan.litheopen.openserver.user.model.User;
import pers.jsan.litheopen.openserver.user.service.ILitheUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import pers.jsan.litheopen.utils.MD5Util;

import java.util.UUID;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jsan
 * @since 2021-10-25
 */
@Service
public class LitheUserServiceImpl extends ServiceImpl<LitheUserMapper, LitheUser> implements ILitheUserService, IUserDetailService {

    @Override
    public UserDetail loadUserMessage(String loginName) {
        User litheUser = new User();
        litheUser.setId(UUID.randomUUID().toString());
        litheUser.setLoginName("jsan");
        litheUser.setName("何键生");
        litheUser.setSalt("123");
        litheUser.setUserStatus(1);
        litheUser.setPassword(MD5Util.encryption32(litheUser.getSalt()+MD5Util.encryption32("123")));
        return litheUser;
    }


    public JSONObject formatOauthUserMessage(UserDetail userDetail) {
        User user = (User) userDetail;
        JSONObject params = new JSONObject();
        params.put("id", user.getId());
        params.put("name", user.getName());
        return params;
    }
}
